-
Notifications
You must be signed in to change notification settings - Fork 924
RU 06-data-storage/02-localstorage #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RU 06-data-storage/02-localstorage #301
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Также в папке еще есть для перевода пара заданий к главе
Please make the requested changes. After it, add a comment "/done". |
/done |
Вижу одно только задание, перевод отправил. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
еще есть пара англ. слов в 1-form-autosave/solution.view/index.html
Please make the requested changes. After it, add a comment "/done". |
/done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Спасибо! Внеси, пожалуйста, изменения.
Когда пользователь закроет страницу и потом откроет ее заново он должен увидеть последнее введенное значение. | ||
|
||
Like this: | ||
Например: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вот пример:
Объекты веб-хранилища `localStorage` и `sessionStorage` позволяют хранить пары ключ/значение в браузере. | ||
|
||
What's interesting about them is that the data survives a page refresh (for `sessionStorage`) and even a full browser restart (for `localStorage`). We'll see that very soon. | ||
Что в них важно - данные, которые в них записаны, сохраняются после обновления страницы (в случае sessionStorage) и даже после перезапуска браузера (при использовании localStorage). Скоро мы это увидим. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что в них важно - данные, которые в них записаны, сохраняются после обновления страницы (в случае sessionStorage
) и даже после перезапуска браузера (при использовании localStorage
). Скоро мы это увидим.
- Unlike cookies, web storage objects are not sent to server with each request. Because of that, we can store much more. Most browsers allow at least 2 megabytes of data (or more) and have settings to configure that. | ||
- Also unlike cookies, the server can't manipulate storage objects via HTTP headers. Everything's done in JavaScript. | ||
- The storage is bound to the origin (domain/protocol/port triplet). That is, different protocols or subdomains infer different storage objects, they can't access data from each other. | ||
- В отличие от кук, объекты веб-хранилища не отправляются на сервер при каждом запросе. Поэтому мы можем хранить гораздо больше данных. Большинство браузеров могут сохранить как минимум 2 мегабайта данных (или больше), и этот размер можно поменять в настройках. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
кук -> куки
- `length` -- количество элементов в хранилище. | ||
|
||
As you can see, it's like a `Map` collection (`setItem/getItem/removeItem`), but also keeps elements order and allows to access by index with `key(index)`. | ||
Как вы видите, интерфейс похож на `Map` (`setItem/getItem/removeItem`), но также запоминается порядок элементов, и можно получить доступ к элементу по индексу -- `key(index)`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Как видим, интерфейс похож на Map
(setItem/getItem/removeItem
), но также запоминается порядок элементов, и можно получить доступ к элементу по индексу -- key(index)
.
``` | ||
|
||
That's allowed for historical reasons, and mostly works, but generally not recommended for two reasons: | ||
Это возможно по историческим причинам и, как правило, работает, но обычно не рекомендуется по двум причинам: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это возможно по историческим причинам и, как правило, работает, но обычно не рекомендуется, потому что:
Обратите внимание, что событие также содержит: `event.url` - url-адрес документа, в котором данные обновились. | ||
|
||
Also, `event.storageArea` contains the storage object -- the event is the same for both `sessionStorage` and `localStorage`, so `storageArea` references the one that was modified. We may even want to set something back in it, to "respond" to a change. | ||
Также `event.storageArea` содержит объект хранилища - событие одно и то же для `sessionStorage` и `localStorage`, поэтому `storageArea` ссылается на то хранилище, которое было изменено. Мы можем захотеть что-то записать в ответ на изменения. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Также event.storageArea
содержит объект хранилища - событие одно и то же для sessionStorage
и localStorage
, поэтому event.storageArea
ссылается на то хранилище, которое было изменено. Мы можем захотеть что-то записать в ответ на изменения.
Объекты веб-хранилища `localStorage` и `sessionStorage` позволяют хранить пары ключ/значение в браузере. | ||
- `key` и `value` должны быть строками. | ||
- Лимит 2 Мб+, зависит от браузера. | ||
- Данные могут храниться неограниченное время. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Данные не имеют "времени истечения".
- `key(index)` -- получить ключ на заданной позиции. | ||
- `length` -- количество элементов в хранилище. | ||
- Используйте `Object.keys` для получения всех ключей. | ||
- Можно использовать ключи в качестве свойств объекта, в этом случае событие `storage` не срабатывает. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Можно обращаться к ключам как к обычным свойствам объекта, в этом случае событие
storage
не срабатывает.
- Contains all the data about the operation, the document `url` and the storage object. | ||
- Triggers on all `window` objects that have access to the storage except the one that generated it (within a tab for `sessionStorage`, globally for `localStorage`). | ||
- Срабатывает при вызове `setItem`, `removeItem`, `clear`. | ||
- Содержит все данные об операции, `url` документа и объект хранилища. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Содержит все данные об произошедшем обновлении (
key/oldValue/newValue
),url
документа и объект хранилищаstorageArea
.
- Triggers on all `window` objects that have access to the storage except the one that generated it (within a tab for `sessionStorage`, globally for `localStorage`). | ||
- Срабатывает при вызове `setItem`, `removeItem`, `clear`. | ||
- Содержит все данные об операции, `url` документа и объект хранилища. | ||
- Срабатывает на всех объектах `window`, которые имеют доступ к хранилищу, а также там, где оно было сгенерировано (на вкладке для `sessionStorage`, глобально для `localStorage`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Срабатывает на всех объектах
window
, которые имеют доступ к хранилищу, кроме того, где оно было сгенерировано (внутри вкладки дляsessionStorage
, глобально дляlocalStorage
).
Please make the requested changes. After it, add a comment "/done". |
/done |
🚀 |
Парни, большое спасибо за терпение! :) |
No description provided.